package com.batyuta.test;

import com.batyuta.ITriangle;
import com.batyuta.TriangleProvider;
import junit.framework.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * User: alexey
 * Date: 6/21/11
 */
@RunWith(value = org.junit.runners.JUnit4.class)
public class TriangleTestCase {

    @Test
    /**
     * Test object to triangle by its sides
     */
    public void testTriangle() throws Exception {
        ITriangle triangle = TriangleProvider.getTriangle();
        Assert.assertNotNull("Object is null", triangle);
        Assert.assertTrue("Incorrect first side", triangle.getLen1() > 0);
        Assert.assertTrue("Incorrect second side", triangle.getLen2() > 0);
        Assert.assertTrue("Incorrect third side", triangle.getLen3() > 0);
        // Used part of Heron's formula
        // http://en.wikipedia.org/wiki/Heron%27s_formula
        double p = ((double) (triangle.getLen1() + triangle.getLen2() + triangle.getLen3())) / 2d;
        double v = (p - triangle.getLen1()) * (p - triangle.getLen2()) * (p - triangle.getLen3());
        Assert.assertTrue("It isn't a Triangle", v > 0);
    }
}
